﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Sharp.Domain.Model;
using Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Common;
using Sharp.Infrastructure;

namespace Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Aggregates
{
    /// <summary>
    /// 流程实例类
    /// </summary>
    [Table("WorkFlow_ProcessInstances")]
    public class ProcessInstanceEntity : IAggregateRoot<int>, ILogCreatedExEntity, ILogModifiEntity
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column(Order = 0)]
        public int Id { get; set; }

        [Required]
        [Column(Order = 1)]
        [MaxLength(100), NonUnicode]
        public string ProcessGUID { get; set; }

        [Required]
        [Column(Order = 2)]
        [MaxLength(50)]
        public string ProcessName { get; set; }

        [Required]
        [Column(Order = 3)]
        [MaxLength(20)]
        public string Version { get; set; }

        [Required]
        [Column(Order = 4)]
        [MaxLength(50)]
        public string AppName { get; set; }

        [Required]
        [Column(Order = 5)]
        [MaxLength(50), NonUnicode]
        public string AppInstanceID { get; set; }

        [Column(Order = 6)]
        [MaxLength(50), NonUnicode]
        public string AppInstanceCode { get; set; }

        [Column(Order = 7)]
        public ProcessStateEnum ProcessState { get; set; }

        [Column(Order = 8)]
        public int? ParentProcessInstanceID { get; set; }

        [Column(Order = 9)]
        [MaxLength(100), NonUnicode]
        public string ParentProcessGUID { get; set; }

        [Column(Order = 10)]
        public int InvokedActivityInstanceID { get; set; }

        [Column(Order = 11)]
        [MaxLength(100), NonUnicode]
        public string InvokedActivityGUID { get; set; }

        [Required]
        [Column(Order = 12)]
        public DateTime? CreatedTime { get; set; }

        [Required]
        [Column(Order = 13)]
        public int? CreatedUserId { get; set; }

        [Required]
        [Column(Order = 14)]
        [MaxLength(50)]
        public string CreatedUserName { get; set; }

        [Column(Order = 15)]
        public DateTime? OverdueDateTime { get; set; }

        [Column(Order = 16)]
        public DateTime? OverdueTreatedDateTime { get; set; }

        [Column(Order = 17)]
        public DateTime? ModifiTime { get; set; }

        [Column(Order = 18)]
        public int? ModifiedUserId { get; set; }

        [Column(Order = 19)]
        public string LastUpdatedByUserName { get; set; }

        [Column(Order = 20)]
        public DateTime? EndedDateTime { get; set; }

        [Column(Order = 21)]
        [MaxLength(50), NonUnicode]
        public string EndedByUserID { get; set; }

        [Column(Order = 22)]
        [MaxLength(50)]
        public string EndedByUserName { get; set; }

        [Required]
        [Column(Order = 23)]
        public byte RecordStatusInvalid { get; set; }

        [Timestamp]
        [Column(Order = 24)]
        public byte[] RowVersionID { get; set; }

        public virtual ICollection<ActivityInstanceEntity> ActivityInstances { get; set; }

        public ICollection<TaskEntity> Tasks { get; set; }
    }
}
